<template>
  <div>
    <el-form
      :model="eidtFrom"
      :rules="rules"
      ref="eidtFrom"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item
        label="  文章标题:"
        prop="title"
      >
        <el-input
          v-model="eidtFrom.title"
          @blur="onblur22"
        ></el-input>
      </el-form-item>
      <el-form-item
        label="  文章内容:"
        prop="body"
      >
        <quill-editor
          v-model="eidtFrom.msg"
          @blur="onblur11"
        > </quill-editor>
        <span style="color:#F56C6C">{{str}}</span>
      </el-form-item>
      <el-form-item label="视频地址:">
        <el-input
          v-model="eidtFrom.videoURL"
          placeholder="请输入视频链接"
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'ArticlesPreview',
  components: {},
  props: {
    title: {
      type: String,
      required: true
    },
    body: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      eidtFrom: {
        title: this.fromtitle,
        videoURL: '',
        msg: ''
      },
      str: '',
      // fromtitle: '',
      editmsg: '',
      rules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ]
      }

    }
  },
  created() {
    this.fromtitle = this.title
    this.frombody = this.body
    this.eidtFrom.title = this.fromtitle

    this.eidtFrom.msg = this.body
    // var re1 = new RegExp('<.+?>', 'g')// 匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
    // this.editmsg = this.frombody.replace(re1, '')// 执行替换成空字符
    // this.eidtFrom.msg = this.editmsg
  },
  mounted() {

  },
  methods: {
    onblur11() {
      if (this.frombody.split(' ').join('').length === 0) {
        this.str = '请输入内容'
      } else {
        this.str = ''
        this.$emit('edit-str', this.eidtFrom)
        this.$emit('edit-rules', this.rules)
      }
    },
    onblur22() {
      this.$emit('edit-str', this.eidtFrom)
      this.$emit('edit-rules', this.rules)
    }
  }

}

</script>

<style lang="less" scoped>
.errorText {
  color: #f56c6c;
}
